#!/usr/bin/env python
import sys
import pygtk, gtk
import gtk.glade
import gtksourceview2
from HollyWidgets.TreeViewBased.TreeView import HTreeView, HTreeNode
from HollyWidgets.TreeViewBased.ExplorerWidget import HExplorerWidget
from TextEditor import TextEditor

class MainWindow():
	
	def __init__( self ):
		#
		gladefile   = "Gui/ui.glade"  
		self.wTree  = gtk.glade.XML( gladefile )
		#widgets
		self.Window          = self.wTree.get_widget("MainWindow")
		self.VProjectSidebar = self.wTree.get_widget("VProjectSidebar")
		self.SExplorerSidebar= self.wTree.get_widget("SExplorerSidebar")
		self.HBody           = self.wTree.get_widget("HBody")
		self.DocumentsTab    = self.wTree.get_widget("DocumentsTab")
		self.CmbFolder       = self.wTree.get_widget("CmbFolder")
		#
		self.ExplorerSidebar = HExplorerWidget.HExplorerWidget()
		self.TextEditor      = TextEditor.TextEditor()
		#add childs
		self.SExplorerSidebar.add( self.ExplorerSidebar )
		self.DocumentsTab.get_nth_page(0).pack_start   ( self.TextEditor    )
		self.DocumentsTab.get_nth_page(0).reorder_child( self.TextEditor, 0 )
		#signals
		self.Window.connect("destroy", self.OnDestroy )
		self.CmbFolder.connect( "current-folder-changed", self.OnCurrentFolderChanged )
		#properties
		self.Window.resize( 640, 480 )
		#show all
		self.Window.show_all()
		
	def RefreshFolderTree( self ):
		path = self.CmbFolder.get_uri().replace( "file://", "" )
		self.ExplorerSidebar.set_base_path( path )
		self.ExplorerSidebar.refresh_list()
		
	def OnCurrentFolderChanged( self, w ):
		self.RefreshFolderTree()
		
	def OnDestroy( self, w ):
		gtk.main_quit()
